package router

import (
	"github.com/gin-contrib/sessions/memstore"
	"go-im-server-demo/src/controller"
	"go-im-server-demo/src/router/middleware"
	"go-im-server-demo/src/ws"
	"sync"

	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

var lock *sync.Mutex = &sync.Mutex{}

func HandleRoutes(client *gin.Engine) {

	// 用于session的支持
	client.Use(sessions.Sessions("my-session", memstore.NewStore([]byte("这是一个私钥用于编解码"))))

	client.Use(middleware.GlobalExceptionHandle)

	// 处理websocket 请求
	client.GET("/ws", ws.HandlerWebsocket)

	// 处理Http请求
	newGroup := client.Group("/sv")
	newGroup.POST("/login", controller.Login)
	newGroup.POST("/sendEmail", controller.SendEmail)

	newGroup.GET("/qrCode", controller.QrCode)
	newGroup.GET("/getUserInfo", controller.GetUserInfo)
	newGroup.POST("/setUserInfo", controller.SetUserInfo)
	newGroup.POST("/vaildScanCode", controller.VaildScanCode)
	newGroup.POST("/scanCode", controller.ScanCode)
	newGroup.POST("/confim", controller.Confim)
}
